Skip to content

fix(api): parse zh-locale usage labels and reset phrases - #2

Merged
v587d merged 1 commit into
v587d:mainfrom
waknow:fix/zh-locale-parsing
Aug 19, 2026
Merged

fix(api): parse zh-locale usage labels and reset phrases#2
v587d merged 1 commit into
v587d:mainfrom
waknow:fix/zh-locale-parsing

Conversation

@waknow

@waknow waknow commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

The opencode.ai dashboard renders the usage page in the UI locale negotiated from the cookie. With oc_locale=zh the data-slot=usage-label values come back as Chinese (rolling/weekly/monthly usage in Chinese) and the reset phrase as Chinese instead of Resets in.

The SSR scraper in src/api.ts only recognizes the English labels and the English reset phrase, so with a zh-locale cookie:

  1. labelToKind matches nothing -> all three windows are dropped
  2. fromSSRHTML returns an empty result
  3. fetchViaCookie treats empty page as a login redirect and throws UsageError('Usage page parsed empty (cookie expired or invalid?)', 'http302')

Net effect: the chip shows err:http302 even though the cookie is perfectly valid.

Fix

  • labelToKind: also recognize the Chinese labels
  • reset-time regex: accept both Resets in and the Chinese phrase prefix
  • parseDurationToSec: accept Chinese time units, including the counter for 1 month

Also rebuilt lib/ (the checked-in build output) so GitHub/npm installs work without a local build.

Tests

  • New zh-locale SSR fixture exercising all three windows with Chinese labels and reset phrases
  • New zh duration cases in the parseDurationToSec table

All 48 tests pass (pnpm test), typecheck and build pass.

@v587d

v587d commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Hi @waknow ,
First of all, a huge thank you for your contribution! I'm really impressed by the quality of your work—especially the thoughtful addition of Chinese localization support and the dark mode logo tweaks.
To help us get this merged smoothly, could you please help with two small things?

1. Rebase on the latest main: Your branch seems to be slightly behind the current main branch. Could you please rebase your changes on top of the latest code? This will ensure we don't run into any merge conflicts.

2. Add screenshots: It would be great if you could add some screenshots demonstrating the Chinese UI to the assets/ folder. This will help future users see the new localization in action.

Let me know if you need any guidance on how to rebase or anything else. Thanks again for making this project better! 🚀

The opencode.ai dashboard renders usage labels in the UI locale. For a
cookie with oc_locale=zh the labels are Chinese (rolling/weekly/monthly
usage) and the reset phrase is '重置于' instead of 'Resets in', so the
SSR scrape parsed every window as empty and the chip showed <err:http302>
(cookie expired or invalid?) despite the cookie being valid.

- labelToKind: recognize the Chinese labels
- reset-time regex: accept both 'Resets in' and '重置于'
- parseDurationToSec: accept Chinese time units (秒/分钟/小时/天/周/月/年)

Adds a zh-locale SSR fixture and zh unit tests.
@waknow
waknow force-pushed the fix/zh-locale-parsing branch from 2763d3f to 21416b6 Compare August 18, 2026 09:56
@waknow

waknow commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @v587d,

Thanks for the review and the kind words! Both points are now handled:

  1. Rebased onto the latest main — the branch now sits on top of 3bfe731 (no more merge conflicts). The only net change vs. main is the zh-locale parsing fix (src/api.ts + rebuilt lib/); all 48 tests, typecheck and build pass.

  2. Screenshots — I'll add the Chinese-UI screenshots to assets/ shortly and link them here.

Thanks again!

@v587d
v587d merged commit 7369957 into v587d:main Aug 19, 2026
@waknow
waknow deleted the fix/zh-locale-parsing branch August 19, 2026 08:48
waknow pushed a commit to waknow/dsh-opencode-go-usage that referenced this pull request Aug 19, 2026
…cale

The old normalizeCookie assumed auth= must be the first segment; a real
browser cookie like 'oc_locale=zh; desktop_promo_dismissed=1; auth=...'
was corrupted into 'auth=oc_locale=zh; ...', which opencode.ai rejects
(302 to login). Fix: locate auth= anywhere, refuse to persist a cookie
with no real auth token, and preserve the pasted oc_locale (default en)
so both English and Chinese (already merged via PR v587d#2) pages parse.
Records decision + rebase notes in COOKIE-FIX.md.
waknow pushed a commit to waknow/dsh-opencode-go-usage that referenced this pull request Aug 19, 2026
…cale

The old normalizeCookie assumed auth= must be the first segment; a real
browser cookie like 'oc_locale=zh; desktop_promo_dismissed=1; auth=...'
was corrupted into 'auth=oc_locale=zh; ...', which opencode.ai rejects
(302 to login). Fix: locate auth= anywhere, refuse to persist a cookie
with no real auth token, and preserve the pasted oc_locale (default en)
so both English and Chinese (already merged via PR v587d#2) pages parse.
Records decision + rebase notes in COOKIE-FIX.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants